// 身份验证审核日志模型 - Mongoose版本
const mongoose = require('mongoose');

const identityAuditLogSchema = new mongoose.Schema({
  applicationId: {
    type: mongoose.Schema.Types.ObjectId,
    required: true,
    index: true,
    comment: '身份验证申请ID'
  },
  reviewerId: {
    type: String,
    required: true,
    index: true,
    comment: '审核人员openid'
  },
  reviewerName: {
    type: String,
    comment: '审核人员姓名'
  },
  action: {
    type: String,
    enum: ['approve', 'reject', 'resubmit'],
    required: true,
    index: true,
    comment: '操作类型：通过/拒绝/重新提交'
  },
  previousStatus: {
    type: String,
    enum: ['not_verified', 'pending', 'approved', 'rejected'],
    comment: '操作前状态'
  },
  newStatus: {
    type: String,
    enum: ['not_verified', 'pending', 'approved', 'rejected'],
    required: true,
    comment: '操作后状态'
  },
  remark: {
    type: String,
    comment: '操作备注'
  },
  operationTime: {
    type: Date,
    default: Date.now,
    index: true,
    comment: '操作时间'
  },
  ipAddress: {
    type: String,
    comment: '操作IP地址'
  },
  userAgent: {
    type: String,
    comment: '用户代理'
  }
}, {
  timestamps: true,
  collection: 'identity_audit_logs'
});

// 创建复合索引
identityAuditLogSchema.index({ applicationId: 1, operationTime: -1 });
identityAuditLogSchema.index({ reviewerId: 1, operationTime: -1 });

module.exports = mongoose.model('IdentityAuditLog', identityAuditLogSchema);